#include "Sequence.h"
#include <stdlib.h>
#include <time.h>

Sequence::Sequence()
{
	srand(time(NULL));
	Clear();
}

void Sequence::Generate()
{
	unsigned char move = 0;
	int randomPos = 0;
	for (int counter = 0; counter < NOOF_MOVES; ++counter)
	{
		// pick a random position
		move = 0;
		randomPos = rand()%NOOF_POSITIONS;
		switch (randomPos)
		{
		case 0:
			move |= LOW;
			break;
		case 1:
			move |= MID;
			break;
		case 2:
			move |= HIGH;
		};

		m_attacks[counter] = move;

		// pick a random position
		move = 0;
		randomPos = rand()%NOOF_POSITIONS;
		switch (randomPos)
		{
		case 0:
			move |= LOW;
			break;
		case 1:
			move |= MID;
			break;
		case 2:
			move |= HIGH;
		};

		m_blocks[counter] = move;
	}
}

void Sequence::Clear()
{
	for (int counter = 0; counter < NOOF_MOVES; ++counter)
	{
		m_attacks[counter] = 0;
		m_blocks[counter] = 0;
	}
}

void Sequence::SetMove(int i_index, MoveType i_type, MovePosition i_position)
{
	switch (i_type)
	{
	case ATTACK:
		m_attacks[i_index] = i_position;
		break;
	case BLOCK:
		m_blocks[i_index] = i_position;
		break;
	};
}

unsigned char Sequence::GetAttack(int i_index) const
{
	return m_attacks[i_index];
}

unsigned char Sequence::GetBlock(int i_index) const
{
	return m_blocks[i_index];
}